package indi.zhang.nacosweb.controller;

import cn.easyes.core.conditions.LambdaEsQueryWrapper;
import com.alibaba.fastjson.JSONObject;
import indi.zhang.common.base.Result;
import indi.zhang.nacosweb.es.domain.Document;
import indi.zhang.nacosweb.es.mapper.DocumentMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

@RestController
//@Api(tags = "test")
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/v1/test")
@Api(tags = {"测试"},description = "测试接口")
public class TestController {

    private final DocumentMapper documentMapper;

    @ApiOperation(value = "es新增接口",notes = "es新增接口")
    @GetMapping("/insert")
    public Integer insert() {
        // 初始化-> 新增数据
        Document document = new Document();
        document.setEsId(UUID.randomUUID().toString());
        document.setTitle("老汉");
        document.setContent("推*技术过硬");
        return documentMapper.insert(document);
    }

    @ApiOperation(value = "es查询接口",notes = "es查询接口")
    @GetMapping("/search")
    public List<Document> search() {
        // 查询出所有标题为老汉的文档列表
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.eq(Document::getTitle, "老汉");
        return documentMapper.selectList(wrapper);
    }

    @PostMapping("/sendTLogMq")
    public Result<Object> sendTLogMq() {
        log.info("hello");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id",2);
        /*MessageContent messageContent = new MessageContent("1", "TEST",jsonObject);
        MsgSenderTemplateUtils.sendEventMessageTLog(messageContent);*/
        return Result.success(null);
    }
    @PostMapping("/sendMq")
    public Result<Object> sendMq() {
        log.info("hello");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id",2);
        // MessageContent messageContent = new MessageContent("1", "TEST2",jsonObject);
        // MsgSenderTemplateUtils.sendEventMessage(messageContent);
        return Result.success(null);
    }
}
